<?php
session_start();
error_reporting(0);
include "./config/connection.php";
if($_SESSION['username']!="")
{

$cari = (isset($_GET['cari'])) ? filter($_GET['cari']) : '';
?>
<!DOCTYPE html>
<html lang="en">
  <head>
     <? include "./include/menuatas.php"; ?>
	  <? include "./include/js.php"; ?>
	  
                   <a href="product_add.php">
                   <button class="btn" type="submit" >
                    <i class="icon-plus"> </i> Tambah Produk
                    </button>
                    </a>   
               </div>
            </div>
            
      <?php
		if(!empty($cari)) $syarat = " AND id_produk like '%$cari%' OR nama_produk like '%$cari%' OR kemasan like '%$cari%' OR harga like '%$cari%' OR berat like '%$cari%'"; 
		else $syarat="";
		$query= "SELECT *
				 FROM produk
				 WHERE 1=1 $syarat ORDER BY id_produk";
		//echo $query;
		$jumData = mysql_num_rows(mysql_query($query));	        
	  ?>
            <div class="search"> 
				<form method="GET" action="">
					<fieldset>
						<input class="text" type="text" name="cari" onblur="if(this.value=='')this.value='pencarian produk...';" onclick="if(this.value=='pencarian produk...')this.value='';"  value="pencarian produk..." />
						<input class="submit" type="submit" value="" />
					</fieldset>
				</form>
			</div> 
		 <?php
		 if(!empty($cari)) echo "<p></p><a href='product.php'>Kembali Ke Data Produk</a> <div style='clear:both'>Ditemukan $jumData data produk dengan kata kunci $cari:</div>";
		
			
			?><table class="table table-striped">							
			<thead>
				<td><b>NO</b></td>
				<td><b>ID PRODUK</b></td>
				<td><b>NAMA PRODUK</b></td>
				<td><b>KEMASAN</b></td>
				<td><b>BERAT/gr</b></td>
				<td><b>HARGA</b></td>
				<td align=right><b>AKSI</b></td>
			</thead>
		<?php
		$item_per_page=10; 
		$offset=paging($item_per_page); $q=$query." LIMIT $offset, $item_per_page";	
		$r=mysql_query($q) or die("Error: Query GAGAL"); $n=mysql_num_rows($r); $no=1;
		if($n>0){
			while($row=mysql_fetch_array($r)){
		?>
			<tr>
				<td><?php echo ($no+$offset);?></td>
				<td><?php echo $row[0];?></td>
				<td><?php echo $row[1];?></td>
				<td><?php echo $row[3];?></td>
				<td><?php echo $row[4];?></td>
				<td><?php echo $row[5];?></td>
				
				<td>
				<a href='product_edit.php?id_produk=<?php echo $row[0];?>' >Edit</a>&nbsp;&nbsp;
				<a  href='product_delete.php?id_produk=<?php echo $row[0];?>' onclick="return confirm('Anda Yakin Akan Menghapus?')" >Hapus</a></td>
			</tr>
			
			 
			<?php
			
			$no++;
			}
			
		}	 
		
		else{
			if(!empty($cari)) $str="Tidak ada data dengan kata kunci <strong>$cari</strong>";
			else $str="Tidak ada data";
			echo "<tr><td colspan='7' align='center'>$str</td></tr>";
		}
			
			echo "</table>";
			echo_paging($jumData,"product.php?cari=$cari&",$item_per_page);			
	?>   
          </div>
          </div><!--/row-->
          </div><!--/row-->
        </div><!--/span-->
      </div><!--/row-->
      </div>	
      <hr>
	<? 
		include "./include/menubawah.php"; ?>
    <?php
    ?>
  </body>
</html>
<?php
    }
else {
    include 'warning.php';
}
?>